package com.wecan.gateway.controller;

import com.wecan.gateway.constant.PropertyConstant;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @Author liuzhihao
 * @Date 2022.01.15
 * @Version 1.0.0
 * @Description 网关controller
 */
@Controller
@RefreshScope
public class ViewController {

    @Value(PropertyConstant.ANNOTATION_GATEWAY_HOME_VERSION)
    private String homeVersion;

    @Value(PropertyConstant.ANNOTATION_GATEWAY_HOME_URL)
    private String homeUrl;

    @Value(PropertyConstant.ANNOTATION_GATEWAY_ANDROID_URL)
    private String androidUrl;

    @Value(PropertyConstant.ANNOTATION_GATEWAY_IPHONE_URL)
    private String iphoneUrl;

    @GetMapping("/")
    public String home(Model model) {
        model.addAttribute("homeVersion", StringUtils.isEmpty(homeVersion) ? "" : "/" + homeVersion);
        model.addAttribute("homeUrl", homeUrl);
        model.addAttribute("androidUrl", androidUrl);
        model.addAttribute("iphoneUrl", iphoneUrl);
        return "home";
    }
}
